﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class RoomParams : Hashtable
	{
		public RoomParams(DataDict dataDict)
		{
			this.parent = dataDict;
		}

		public DataDict Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public int AddRoomParam(RoomParam roomParam)
		{
			int result;
			try
			{
				roomParam.Parent = this;
				int num = this.parent.Parent.AddCurrID();
				roomParam.ID = num;
				this.Add(num, roomParam);
				this.parent.Parent.hCurrIDList.Add(num, roomParam);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveRoomParam(int ID)
		{
			try
			{
				this.Remove(ID);
				this.parent.Parent.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public RoomParam GetRoomParam(int ID)
		{
			RoomParam result;
			try
			{
				result = (RoomParam)this[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadRoomParam(RoomParam roomParam)
		{
			bool result;
			try
			{
				roomParam.Parent = this;
				int id = roomParam.ID;
				if (this.parent.Parent.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.parent.Parent.CurrID)
					{
						this.parent.Parent.CurrID = id;
					}
					this.Add(id, roomParam);
					this.parent.Parent.hCurrIDList.Add(id, roomParam);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private DataDict parent;
	}
}
